<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
	<meta charset="utf-8" />
	<title></title>
	<meta name="description" content="overview & stats" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<link rel="stylesheet" href="static/css/bootstrap.min.css" />
	<link rel="stylesheet" href="static/css/bootstrap-responsive.min.css" />
	<link rel="stylesheet" href="static/css/font-awesome.min.css" />
	<link rel="stylesheet" href="static/css/ace.min.css" />
	<link rel="stylesheet" href="static/css/ace-responsive.min.css" />
	<link rel="stylesheet" href="static/css/ace-skins.min.css" />
	
	<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
	<!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
</head>

<script type="text/javascript">
	$(top.hangge());
	
	//保存
	function saveDictionaryCatalog(){
		if($("#diccode").val()==""){
			$("#diccode").tips({
				side:3,
	            msg:'请输入字典字典编码',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#diccode").focus();
			return false;
		}
		
		if($("#dicvalue").val()=="" || $("#dicvalue").val()=="此编码已存在!"){
			$("#dicvalue").tips({
				side:3,
	            msg:'请输入编码',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#dicvalue").focus();
			$("#dicvalue").val('');
			$("#dicvalue").css("background-color","white");
			return false;
		}
		
		if($("#sort").val()==""){
			$("#sort").tips({
				side:1,
	            msg:'请输入序号',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#sort").focus();
			return false;
		}
		
		if(isNaN(Number($("#sort").val()))){
			$("#sort").tips({
				side:1,
	            msg:'请输入数字',
	            bg:'#AE81FF',
	            time:2
	        });
			
			$("#sort").focus();
			$("#sort").val(1);
			return false;
		}
		
		hasDicCode();
		
	}
	
	//判断编码是否存在
	function hasDicCode(){
		var catacode = $("#catacode").val();
		var dicvalue = $("#dicvalue").val();
		$.ajax({
			type : "PUT",
			url : "dictionary/hasDicCode/"+catacode + "/"+ dicvalue+"/"+ ".json",
			//data:JSON.stringify(dicvalue),
			contentType:"application/json",  //发送至服务器的类型
			//dataType : "json",     //预期服务器返回类型
			success: function(data){
				//alert(data);
				//return false;
				if(data=="error"){
					$("#dicvalue").css("background-color","#D16E6C");
					setTimeout("$('#dicvalue').val('此编码值已存在!')",500);
				}else{
					$("#DictionaryForm").submit();
					$("#centerOfMainFrame").hide();
					$("#centerOfMainFrame2").show();
				}
			}
		})
	}
</script>
<body>
	<form  action="dictionary/saveDictionary.do" name="DictionaryForm" id="DictionaryForm" method="POST" >
		<input type="hidden" id="catacode" name="catacode" value="${pageData.catacode }">
		<div id="centerOfMainFrame">
			<table>
				<tr class="info">
					<td><input type="text" name="diccode" id="diccode" placeholder="这里输入字典编码" title="名称"/></td>
				</tr>
				<tr class="info">
					<td><input type="text" name="dicvalue" id="dicvalue" placeholder="这里输入字典值" title="编码"/></td>
				</tr>
				<tr class="info">
					<td><input type="number" name="sort" id="sort" placeholder="这里输入序号" title="序号"/></td>
				</tr>
				<tr>
					<td style="text-align: center;">
						<a class="btn btn-mini btn-primary" onclick="saveDictionaryCatalog();">保存</a>
						<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
					</td>
				</tr>
			</table>
		</div>
		<div id="centerOfMainFrame2" class="center" style="display:none"><br/><br/><br/><img src="static/images/jzx.gif" style="width: 50px;" /><br/><h4 class="lighter block green"></h4></div>
	</form>
</body>
</html>